﻿Imports System.Data
Imports MyGeneration.dOOdads
Public Class rc_Empleados

    Private _MessageError As Exception = Nothing
    Public Property MessageError() As Exception
        Get
            Return _MessageError
        End Get
        Set(ByVal value As Exception)
            _MessageError = value
        End Set
    End Property


#Region "Empleados"

    Public Function Insert_Empleado(ByVal conn As String, ByVal codemp As Integer, ByVal nroemp As Integer, ByVal nombre As String, ByVal apellido As String, ByVal direccion As String, ByVal codCiudad As Integer, ByVal telefono As String, ByVal celular As String,
                                     ByVal nroci As Integer, ByVal fechaingreso As DateTime, ByVal codtipoemp As Integer, ByVal codcategoria As Integer,
                                     ByVal nrolegajo As Integer, ByVal fechanacimiento As DateTime) As Integer

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim empleado As New Class_RC_Data.Class_RC.EMPLEADOS(conn)

            empleado.AddNew()
            empleado.NroEmp = nroemp
            empleado.Nombre = nombre
            empleado.Apellido = apellido
            empleado.Direccion = direccion
            empleado.CodCiudad = codCiudad
            empleado.Telefono = telefono
            empleado.Celular = celular
            empleado.NroCi = nroci
            empleado.FechaIngreso = fechaingreso
            empleado.CodTipoEmp = codtipoemp
            empleado.CodCategoria = codcategoria
            empleado.NroLegajo = nrolegajo
            empleado.FechaNac = fechanacimiento
            empleado.Save()

            tx.CommitTransaction()

            Return empleado.CodEmp

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return 0
        End Try

    End Function

    Public Function Update_Empleado(ByVal conn As String, ByVal codemp As Integer, ByVal nroemp As Integer, ByVal apellido As String, ByVal nombre As String, ByVal direccion As String, ByVal codCiudad As Integer, ByVal telefono As String, ByVal celular As String,
                                     ByVal nroci As Integer, ByVal fechaingreso As DateTime, ByVal codtipoemp As Integer, ByVal codcategoria As Integer,
                                     ByVal nrolegajo As Integer, ByVal fechanacimiento As DateTime) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim empleado As New Class_RC_Data.Class_RC.EMPLEADOS(conn)
            empleado.Where.CodEmp.Value = codemp

            If empleado.Query.Load Then

                empleado.NroEmp = nroemp
                empleado.Nombre = nombre
                empleado.Apellido = apellido
                empleado.Direccion = direccion
                empleado.CodCiudad = codCiudad
                empleado.Telefono = telefono
                empleado.Celular = celular
                empleado.NroCi = nroci
                empleado.FechaIngreso = fechaingreso
                empleado.CodTipoEmp = codtipoemp
                empleado.CodCategoria = codcategoria
                empleado.NroLegajo = nrolegajo
                empleado.FechaNac = fechanacimiento
                empleado.Save()

            End If

            tx.CommitTransaction()
            Return True

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function Delete_Empleado(ByVal conn As String, ByVal codemp As Integer) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()
            Dim empleado As New Class_RC_Data.Class_RC.EMPLEADOS(conn)
            empleado.Where.CodEmp.Value = codemp

            If empleado.Query.Load Then

                empleado.MarkAsDeleted()
                empleado.Save()

            End If

            tx.CommitTransaction()
            Return True

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function get_Empleados_All(ByVal conn As String, ByVal codemp As Integer, ByVal nombre As String, ByVal Apellido As String, ByVal codCiudad As Integer,
                                      ByVal codtipoemp As Integer, ByVal codcategoria As Integer) As DataTable
        Try

            Dim vempleados As New Class_RC_Data.Class_RC.VistaEmpleados(conn)

            If codemp > 0 Then
                vempleados.Where.CodEmp.Value = codemp
            End If

            If nombre <> "" Then
                vempleados.Where.Nombre.Value = "%" & nombre & "%"
                vempleados.Where.Nombre.Operator = WhereParameter.Operand.Like
            End If
            If Apellido <> "" Then
                vempleados.Where.Apellido.Value = "%" & Apellido & "%"
                vempleados.Where.Apellido.Operator = WhereParameter.Operand.Like
            End If
            If codtipoemp > 0 Then
                vempleados.Where.CodTipoEmp.Value = codtipoemp
            End If

            If codCiudad > 0 Then
                vempleados.Where.CodCiudad.Value = codCiudad
            End If

            If codcategoria > 0 Then
                vempleados.Where.CodCategoria.Value = codcategoria
            End If

            If vempleados.Query.Load Then
                If vempleados.DefaultView.Table.Rows.Count > 0 Then
                    Return vempleados.DefaultView.Table
                Else
                    Return Nothing
                End If

            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    
    Public Function get_tipo_Empleado(ByVal conn As String) As DataTable

        Try
            Dim vTipoEmpleado As New Class_RC_Data.Class_RC.TIPOEMPLEADO(conn)

            If vTipoEmpleado.Query.Load Then
                If vTipoEmpleado.DefaultView.Table.Rows.Count > 0 Then
                    Return vTipoEmpleado.DefaultView.Table
                Else
                    Return Nothing
                End If
            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function
    Public Function get_Categoria(ByVal conn As String, ByVal codtipoemp As Integer) As DataTable
        Try
            Dim vCategoria As New Class_RC_Data.Class_RC.CATEGORIAS(conn)

            If codtipoemp > 0 Then
                vCategoria.Where.CodTipoEmp.Value = codtipoemp
            End If

            If vCategoria.Query.Load Then
                If vCategoria.DefaultView.Table.Rows.Count > 0 Then
                    Return vCategoria.DefaultView.Table
                Else
                    Return Nothing
                End If
            Else
                Return Nothing

            End If
        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    Public Function get_Ciudades(ByVal conn As String) As DataTable
        Try
            Dim vTipoCiudad As New Class_RC_Data.Class_RC.CIUDAD(conn)
            If vTipoCiudad.Query.Load Then
                If vTipoCiudad.DefaultView.Table.Rows.Count > 0 Then
                    Return vTipoCiudad.DefaultView.Table
                Else
                    Return Nothing
                End If

            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    
#End Region

    Private Function DateTime() As Date
        Throw New NotImplementedException
    End Function

    Function Insert_Empleado(ByVal dbConn As String, ByVal p2 As String, ByVal p3 As String, ByVal p4 As String, ByVal p5 As String, ByVal p6 As String, ByVal p7 As Object, ByVal p8 As String, ByVal p9 As String, ByVal p10 As String, ByVal p11 As Date, ByVal p12 As Object, ByVal p13 As Object, ByVal p14 As Date) As Integer
        Throw New NotImplementedException
    End Function

#Region "Tipo Empleado"
    Public Function Insert_TipoEmpleado(ByVal conn As String, ByVal desctipoemp As String, ByVal obstipoemp As String) As Integer

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim tipoEmp As New Class_RC_Data.Class_RC.TIPOEMPLEADO(conn)

            tipoEmp.AddNew()
            tipoEmp.DescTipoEmp = desctipoemp
            tipoEmp.ObsTipoEmp = obstipoemp
            tipoEmp.Save()
            tx.CommitTransaction()

            Return tipoEmp.CodTipoEmp

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return 0
        End Try

    End Function

    Public Function Update_TipoEmpleado(ByVal conn As String, ByVal codtipoemp As Integer, ByVal desctipoemp As String, ByVal obstipoemp As String) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim tipoEmp As New Class_RC_Data.Class_RC.TIPOEMPLEADO(conn)
            tipoEmp.Where.CodTipoEmp.Value = codtipoemp

            If tipoEmp.Query.Load Then

                tipoEmp.DescTipoEmp = desctipoemp
                tipoEmp.ObsTipoEmp = obstipoemp
                tipoEmp.Save()

            End If

            tx.CommitTransaction()
            Return True

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function Delete_TipoEmp(ByVal conn As String, ByVal codtipoemp As Integer) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim tipoEmp As New Class_RC_Data.Class_RC.TIPOEMPLEADO(conn)
            tipoEmp.Where.CodTipoEmp.Value = codtipoemp

            If tipoEmp.Query.Load Then

                tipoEmp.MarkAsDeleted()
                tipoEmp.Save()

            End If

            tx.CommitTransaction()
            Return True

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function get_TipoEmpleado_All(ByVal conn As String, ByVal codtipoemp As Integer, ByVal desctipoemp As String) As DataTable
        Try

            Dim tipoEmp As New Class_RC_Data.Class_RC.TIPOEMPLEADO(conn)

            If codtipoemp > 0 Then
                tipoEmp.Where.CodTipoEmp.Value = codtipoemp
            End If

            If desctipoemp <> "" Then
                tipoEmp.Where.DescTipoEmp.Value = "%" & desctipoemp & "%"
                tipoEmp.Where.DescTipoEmp.Operator = WhereParameter.Operand.Like
            End If

            If tipoEmp.Query.Load Then
                If tipoEmp.DefaultView.Table.Rows.Count > 0 Then
                    Return tipoEmp.DefaultView.Table
                Else
                    Return Nothing
                End If

            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function
#End Region
#Region "Categoria"
    Public Function Insert_Categoria(ByVal conn As String, ByVal descCategoria As String, ByVal codTipoEmp As Integer, ByVal jormalBase As Decimal, ByVal horasTrab As Integer, ByVal salHora As Decimal) As Integer

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim Categoria As New Class_RC_Data.Class_RC.CATEGORIAS(conn)

            Categoria.AddNew()
            Categoria.DescCategoria = descCategoria
            Categoria.CodTipoEmp = codTipoEmp
            Categoria.JornalBase = jormalBase
            Categoria.HorasTrab = horasTrab
            Categoria.SalHora = salHora
            Categoria.Save()
            tx.CommitTransaction()

            Return Categoria.CodCategoria

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return 0
        End Try

    End Function

    Public Function Update_Categoria(ByVal conn As String, ByVal codCategoria As Integer, ByVal descCategoria As String, ByVal codTipoEmp As Integer, ByVal jormalBase As Decimal, ByVal horasTrab As Integer, ByVal salHora As Decimal) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim Categoria As New Class_RC_Data.Class_RC.CATEGORIAS(conn)
            Categoria.Where.CodCategoria.Value = codCategoria

            If Categoria.Query.Load Then

                Categoria.DescCategoria = descCategoria
                Categoria.CodTipoEmp = codTipoEmp
                Categoria.JornalBase = jormalBase
                Categoria.HorasTrab = horasTrab
                Categoria.SalHora = salHora
                Categoria.Save()

            End If

            tx.CommitTransaction()
            Return True

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function Delete_Categoria(ByVal conn As String, ByVal codCategoria As Integer) As Boolean

        Dim tx As TransactionMgr
        tx = TransactionMgr.ThreadTransactionMgr()

        Try
            tx.BeginTransaction()

            Dim Categoria As New Class_RC_Data.Class_RC.CATEGORIAS(conn)
            Categoria.Where.CodCategoria.Value = codCategoria

            If Categoria.Query.Load Then

                Categoria.MarkAsDeleted()
                Categoria.Save()

            End If

            tx.CommitTransaction()
            Return True

        Catch ex As Exception
            tx.RollbackTransaction()
            MessageError = ex
            Return False
        End Try

    End Function

    Public Function get_Categoria_All(ByVal conn As String, ByVal codCategoria As Integer, ByVal descCategoria As String, ByVal codTipoEmp As Integer) As DataTable
        Try

            Dim Categoria As New Class_RC_Data.Class_RC.VistaCategorias(conn)

            If codCategoria > 0 Then
                Categoria.Where.CodCategoria.Value = codCategoria
            End If

            If descCategoria <> "" Then
                Categoria.Where.DescCategoria.Value = "%" & descCategoria & "%"
                Categoria.Where.DescCategoria.Operator = WhereParameter.Operand.Like
            End If

            If codTipoEmp > 0 Then
                Categoria.Where.CodTipoEmp.Value = codTipoEmp
            End If

            If Categoria.Query.Load Then
                If Categoria.DefaultView.Table.Rows.Count > 0 Then
                    Return Categoria.DefaultView.Table
                Else
                    Return Nothing
                End If

            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function

    Public Function get_tipo_Emp(ByVal conn As String, ByVal codtipoemp As Integer) As DataTable
        Try
            Dim vTipoEmpleado As New Class_RC_Data.Class_RC.TIPOEMPLEADO(conn)
            If codtipoemp > 0 Then
                vTipoEmpleado.Where.CodTipoEmp.Value = codtipoemp
            End If
            If vTipoEmpleado.Query.Load Then
                If vTipoEmpleado.DefaultView.Table.Rows.Count > 0 Then
                    Return vTipoEmpleado.DefaultView.Table
                Else
                    Return Nothing
                End If
            Else
                Return Nothing

            End If

        Catch ex As Exception
            MessageError = ex
            Return Nothing
        End Try

    End Function
#End Region

End Class
